<?php
/**
 * @Author: liuhongbin
 * @Email: 514660094@qq.com
 * @Date: 2019-02-12 16:15:10
 * @Description:
 * @LastEditors: liuhongbin
 * @LastEditTime: xxx
 */

namespace app\common\model\wechat;

use app\common\model\AdminBaseModel;
use app\common\model\wechat\tralts\WechatModel;

class WechatOrder extends AdminBaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'wechat_order';

    /**
     * 字段类型或者格式转换
     * @var array
     */
    protected $type = [

    ];

    use WechatModel;

    public function Shares()
    {
        return $this->hasMany(WechatShare::class, 'transaction_id', 'transaction_id')->append([]);
    }

    public function getShareAttr($val, $data)
    {
        $res = [];
        $res['count'] = (new WechatShare())->where(['transaction_id' => $data['transaction_id']])->count();//分账单数量
        $res['receivers_count'] = (new WechatShareReceiver())->where(['transaction_id' => $data['transaction_id'], 'type' => 'PERSONAL_OPENID'])->count();//参数分账用户数
        return $res;
    }
}
